using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 智慧大棚课件
{





    public class SqlHelper
    {
        //连接字符串
        private static string connStr = ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;


      




        // 查询
        public static SqlDataReader SelectResult(string sql)
        {

            SqlConnection conn = new SqlConnection(connStr);

            SqlCommand cmd = new SqlCommand(sql, conn);


            try
            {
                conn.Open();

                SqlDataReader reader = cmd.ExecuteReader();

                return reader;

            }
            catch (Exception ex)
            {

                System.Windows.Forms.MessageBox.Show("sqlError");

                return null;
            }



        }


        // 增删改
        public static int Update(string sql)
        {
            SqlConnection conn = new SqlConnection(connStr);

            SqlCommand cmd = new SqlCommand(sql, conn);

            try
            {

                conn.Open();

               int count =  cmd.ExecuteNonQuery();

                return count;

            }
            catch (Exception)
            {

                System.Windows.Forms.MessageBox.Show("Sql Error");
                return 0;
            }

        }



        // 事务



    }
}
